#include <wx/panel.h>
#include <wx/dcclient.h>
#include <wx/image.h>
#include <wx/msgdlg.h>
#include <functional>
#include <cstring>

class ImageDisplay : public wxPanel
{
public:
    ImageDisplay(wxWindow* parent);
    virtual ~ImageDisplay();
    //传入图片必须3通道并且必须是malloc分配，并且会自动管理指针，无需外部释放
    void SetImage(unsigned char* _imageData,long _height,long _width);
    void SetImage(wxImage& image);
    void HandleImage(int Threshold);
    void FilterImage(int Threshold);
    void SetHandleArea(long xx,long yy);
    //一个快捷处理函数，前提是图像的高和宽已经设置好了
    //图片基本参数通过SetImage设置
    //输入的数据为单通道
    wxPoint GetGrayCenter(unsigned char* _imageData,int Threshold);
    //该函数会将数据移动到起内部，外部plist将被释放
    void LinkPoints(wxPointList& plist);
    wxPoint GetTargetPos();

private:
    void doImageSet(long width,long height);
    //如果图片中找不到任何有用数据将抛出异常(int)1
    wxPoint grayCenter(int Threshold);
    long PixelValue(int pixelValue,int Threshold); //计算参与计算的像素值
    long calSumValue(std::function<long(int,int)> func_X_Y); //对整个图像求和
    wxImage currentImage;
    long HandleAreaX=10;
    long HandleAreaY=10;
    wxImage fliterResImage;
    wxPoint MarkPos;
    wxPointList pointList;
    bool displayPosInf=false;
    bool displayRawImage=true;
    bool displayFilterImage=false;
    bool displayHandleArea=true;
    bool displayPointLinks=false;
    void OnPaint(wxPaintEvent& event);
    void DrawPos(wxPoint pos,wxPaintDC& dc); //绘制坐标
    void DrawHandleArea(wxPaintDC& dc);
    void DrawLinkPoints(wxPaintDC& dc);
    wxPoint SaclePos(wxPoint pos);  //缩放坐标
    void ReversalColor(unsigned char* imageData,size_t size);
    unsigned char* RouteImage(unsigned char* imageData,size_t size);
};